# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Fredy García <frealgagu at gmail dot com>

pkgname=just
pkgver=1.13.0
pkgrel=1
pkgdesc="A handy way to save and run project-specific commands"
arch=("loong64" "x86_64")
url="https://github.com/casey/just"
license=("custom:CC0")
depends=("gcc-libs")
makedepends=("cargo")
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/casey/${pkgname}/archive/${pkgver}.tar.gz")
sha256sums=('ead24ef982253fa4bdd0af27b0867f74c8d9528817be8dd8b14b182369a432c7')

prepare() {
  cd "${pkgname}-${pkgver}"
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "${pkgname}-${pkgver}"
  find -name Cargo.lock -exec rm -f {} \;
  mkdir -p .cargo
  cat > .cargo/config.toml <<EOF
[source.crates-io]
registry = "https://gitee.com/yetist/crates.io-index"
EOF
  cargo build --release
}

check() {
  cd "${pkgname}-${pkgver}"
  cargo check --frozen --release
}

package() {
  cd "${pkgname}-${pkgver}"
  install -Dm755 "target/release/${pkgname}" "${pkgdir}/usr/bin/${pkgname}"
  install -Dm644 "LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install -Dm644 "completions/just.zsh" "${pkgdir}/usr/share/zsh/site-functions/_just"
  install -Dm644 "completions/just.bash" "${pkgdir}/usr/share/bash-completion/completions/just"
  install -Dm644 "completions/just.fish" "${pkgdir}/usr/share/fish/vendor_completions.d/just.fish"
}
